Completed
Pull Request — master (#26)
by Juliette
05:21
created

$(document).ready   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
c 0
b 0
f 0
nc 3
nop 2
dl 0
loc 1
rs 9.2
1
/* Javascript interaction for PHP cheat sheets */
2
jQuery(document).ready(function(){var myAccordion;var phpvForm;var myTabs;var formTabField;var windowTitle;var tabPanels;myAccordion=jQuery("#accordion");myAccordion.accordion({active:false,collapsible:true,icons:{header:"ui-icon-circle-arrow-e",activeHeader:"ui-icon-circle-arrow-s"},heightStyle:"content"});phpvForm=jQuery("#choose-version");phpvForm.on("change","select",function(){phpvForm.submit()});myTabs=jQuery("#tabs");formTabField=jQuery("#phpv-tab");windowTitle=jQuery("title");myTabs.tabs({beforeActivate:function(event,ui){var oldId=ui.oldPanel.find("table").attr("id");if(oldId){jQuery("#"+oldId).thfloat("destroy")}},activate:function(event,ui){var tableId;var tabHref;var tabTab;var tabTitle;tableId=ui.newPanel.find("table").attr("id");if(tableId){jQuery("#"+tableId).thfloat({side:"head",onShow:function(table,block){block.find("th").css("background","")}}).thfloat({side:"foot",onShow:function(table,block){block.find("th").css("background","")}})}jQuery(".hover, .sticky").removeClass("hover sticky");tabHref=ui.newTab.find("a").attr("href");tabTab=ui.newTab.find("a").attr("data-tab");tabTitle=ui.newTab.find("a").attr("data-tab-title");if(tabHref&&tabTab&&tabTitle){var oldTab=ui.oldTab.find("a").attr("data-tab");var oldTitle=ui.oldTab.find("a").attr("data-tab-title");var titleText=windowTitle.text();if(titleText.indexOf(":: "+oldTitle)!==-1){titleText=titleText.replace(":: "+oldTitle,":: "+tabTitle)}else{var oldTabNoUnderscore=oldTab.replace("_"," ");if(titleText.indexOf(":: "+oldTabNoUnderscore)!==-1){titleText=titleText.replace(":: "+oldTabNoUnderscore,":: "+tabTitle)}else{var oldTitlePre=titleText.substring(0,titleText.indexOf(" Cheatsheet for "));titleText=oldTitlePre+titleText.replace(oldTitlePre," :: "+tabTitle)}}if(tabHref.substring(0,1)==="#"){var oldUri=window.location.href;if(oldUri.indexOf("#")!==-1&&window.location.hash==="#"+oldTab){tabHref=oldUri.replace(window.location.hash,tabHref)}else{tabHref=oldUri+tabHref}}else{tabHref=tabHref.substring(0,tabHref.indexOf("/ajax")+1)}history.pushState(null,titleText,tabHref);windowTitle.text(titleText);formTabField.val(tabTab)}},beforeLoad:function(event,ui){if(ui.panel.html()===""){ui.panel.html('<div class="spinner">&nbsp;</div>');ui.jqXHR.error(function(){ui.panel.html("An error occurred while loading the table. Please try again. If it keeps failing, please inform the site owner.")});return true}return false},cache:true,create:function(event,ui){var tabHash=window.location.hash;if(tabHash&&tabHash!==""){if(formTabField.val()===""){formTabField.val(tabHash.replace("#",""))}var tabTitle=ui.tab.find("a").attr("data-tab-title");var titleText=windowTitle.text();var oldTitlePre=titleText.substring(0,titleText.indexOf(" Cheatsheet for "));titleText=oldTitlePre+titleText.replace(oldTitlePre," :: "+tabTitle);windowTitle.text(titleText)}},load:function(event,ui){var tableId=ui.panel.find("table").attr("id");jQuery("#"+tableId).thfloat({side:"head",onShow:function(table,block){block.find("th").css("background","")}}).thfloat({side:"foot",onShow:function(table,block){block.find("th").css("background","")}})}});myTabs.on("click",".fright a",function(){myAccordion.accordion("option","active",1)});jQuery(".ui-tabs-panel th [title]").tooltip({tooltipClass:"th-tooltip",content:function(){var element=jQuery(this);var toolTip;toolTip=element.attr("title");toolTip=toolTip.replace(/\n/g,"<br />");toolTip=toolTip.replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;");return toolTip}});tabPanels=jQuery(".ui-tabs-panel");tabPanels.on("mouseenter","td, th",function(){var idx=jQuery(this).parent().children("td,th").index(jQuery(this))+1;var rowIdx=jQuery(this).parent().parent().children("tr").index(jQuery(this).parent())+1;if(rowIdx>1){jQuery(this).parent().addClass("hover")}if(idx>1){jQuery(".ui-tabs-panel td:nth-child("+idx+")").addClass("hover");jQuery(".ui-tabs-panel th:nth-child("+idx+")").addClass("hover");jQuery(".thfloat th:nth-child("+idx+")").addClass("hover")}});tabPanels.on("mouseleave","td, th",function(){var idx=jQuery(this).parent().children("td,th").index(jQuery(this))+1;var rowIdx=jQuery(this).parent().parent().children("tr").index(jQuery(this).parent())+1;if(rowIdx>1){jQuery(this).parent().removeClass("hover")}if(idx>1){jQuery(".ui-tabs-panel td:nth-child("+idx+")").removeClass("hover");jQuery(".ui-tabs-panel th:nth-child("+idx+")").removeClass("hover");jQuery(".thfloat th:nth-child("+idx+")").removeClass("hover")}});tabPanels.on("click","td, th",function(){var idx=jQuery(this).parent().children("td,th").index(jQuery(this))+1;var rowIdx=jQuery(this).parent().parent().children("tr").index(jQuery(this).parent())+1;var tCells=jQuery(".ui-tabs-panel td:nth-child("+idx+")");var tHeaders=jQuery(".ui-tabs-panel th:nth-child("+idx+")");var fHeaders=jQuery(".thfloat th:nth-child("+idx+")");if(jQuery(this).parent().hasClass("sticky")||jQuery("td:nth-child("+idx+")").hasClass("sticky")||jQuery("th:nth-child("+idx+")").hasClass("sticky")){if(rowIdx>1){jQuery(this).parent().removeClass("sticky")}if(idx>1){tCells.removeClass("sticky");tHeaders.removeClass("sticky");fHeaders.removeClass("sticky")}}else{if(rowIdx>1){jQuery(this).parent().addClass("sticky")}if(idx>1){tCells.addClass("sticky");tHeaders.addClass("sticky");fHeaders.addClass("sticky")}}})});
2 ignored issues
show
Coding Style introduced by
As per coding-style, prefer block-scoped variables using let or const which have better semantics than var.

Since ECMAScript 6, you can create block-scoped vars or constants with the keywords let or const. These variables/constants are only valid in the code block where they have been declared.

Consider the following two pieces of code:

if (true)
 {
    var x = "Hello, Stonehenge!";
}

console.log(x); //prints Hello, Stonehenge! to the console

and

if (true)
 {
    let x = "Hello, Stonehenge!";
}

console.log(x); //ReferenceError: x is not defined

The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.

To know more about this ECMA6 feature, look at the MDN pages on let and const.

Loading history...
Bug introduced by
The variable history seems to be never declared. If this is a global, consider adding a /** global: history */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
3